﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Vision001.Base
{
    public class NewCommand : ICommand
    {
        public NewCommand(Action<object> execute, Func<bool> canExecute = null)
        {
            ExeAction = execute;
            Canexecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            return Canexecute?.Invoke() ?? true;
        }

        public void Execute(object parameter)
        {
            ExeAction?.Invoke(parameter);
        }

        public event EventHandler CanExecuteChanged
        {
            add => CommandManager.RequerySuggested += value;
            remove => CommandManager.RequerySuggested -= value;
        }

        public Func<bool> Canexecute;

        public Action<object> ExeAction;
    }
}